gl: avoid copying GskGLCachedGlyph in lookup
authorChristian Hergert <chergert@redhat.com>
Wed, 9 Oct 2019 21:27:48 +0000 (14:27 -0700)
committerChristian Hergert <chergert@redhat.com>
Wed, 9 Oct 2019 21:37:08 +0000 (14:37 -0700)
This saves a minor amount of CPU time by avoiding the copy of structure
on each lookup (which is short-lived).

gsk/gl/gskglglyphcache.c
gsk/gl/gskglglyphcacheprivate.h
gsk/gl/gskglrenderer.c

index 81e94819445c116671b998a4978519c150d45066..5e31369057f35965f9b088302aa155951c744bc6 100644 (file)
@@ -256,14 +256,14 @@ add_to_cache (GskGLGlyphCache  *self,
 #define PHASE(x) ((int)(floor (4 * (x + 0.125)) - 4 * floor (x + 0.125)))
 
 gboolean
-gsk_gl_glyph_cache_lookup (GskGLGlyphCache  *cache,
-                           PangoFont        *font,
-                           PangoGlyph        glyph,
-                           float             x,
-                           float             y,
-                           float             scale,
-                           GskGLDriver      *driver,
-                           GskGLCachedGlyph *cached_glyph_out)
+gsk_gl_glyph_cache_lookup (GskGLGlyphCache         *cache,
+                           PangoFont               *font,
+                           PangoGlyph               glyph,
+                           float                    x,
+                           float                    y,
+                           float                    scale,
+                           GskGLDriver             *driver,
+                           const GskGLCachedGlyph **cached_glyph_out)
 {
   GskGLCachedGlyph *value;
   guint xshift = PHASE (x);
@@ -333,15 +333,15 @@ gsk_gl_glyph_cache_lookup (GskGLGlyphCache  *cache,
           value->draw_height * key->scale / 1024 > 0)
         add_to_cache (cache, key, driver, value);
 
-      *cached_glyph_out = *value;
+      *cached_glyph_out = value;
       g_hash_table_insert (cache->hash_table, key, value);
     }
   else
     {
-      *cached_glyph_out = *value;
+      *cached_glyph_out = value;
     }
 
-  return cached_glyph_out->atlas != NULL;
+  return (*cached_glyph_out)->atlas != NULL;
 }
 
 void
index ee1912c3a6a8e54aa3803315a01c15a89919f40f..8d669df6e1aa42f3038bb0927af782e008f3d81f 100644 (file)
@@ -61,6 +61,6 @@ gboolean                 gsk_gl_glyph_cache_lookup          (GskGLGlyphCache
                                                              float                   y,
                                                              float                   scale,
                                                              GskGLDriver            *driver,
-                                                             GskGLCachedGlyph       *cached_glyph_out);
+                                                             const GskGLCachedGlyph **cached_glyph_out);
 
 #endif
index 25b4c9b4208f4f872c3d45e658c9e8f4f05e636d..118b67c0ec0b59fe7dd0792eeaa2587b1c49a8dd 100644 (file)
@@ -584,7 +584,7 @@ render_text_node (GskGLRenderer   *self,
   for (i = 0; i < num_glyphs; i++)
     {
       const PangoGlyphInfo *gi = &glyphs[i];
-      GskGLCachedGlyph glyph;
+      const GskGLCachedGlyph *glyph;
       float glyph_x, glyph_y, glyph_w, glyph_h;
       float tx, ty, tx2, ty2;
       double cx;
@@ -606,23 +606,23 @@ render_text_node (GskGLRenderer   *self,
                                  &glyph);
 
       /* e.g. whitespace */
-      if (glyph.draw_width <= 0 || glyph.draw_height <= 0)
+      if (glyph->draw_width <= 0 || glyph->draw_height <= 0)
         goto next;
 
-      if (glyph.texture_id == 0)
+      if (glyph->texture_id == 0)
         goto next;
 
-      ops_set_texture (builder, glyph.texture_id);
+      ops_set_texture (builder, glyph->texture_id);
 
-      tx  = glyph.tx;
-      ty  = glyph.ty;
-      tx2 = tx + glyph.tw;
-      ty2 = ty + glyph.th;
+      tx  = glyph->tx;
+      ty  = glyph->ty;
+      tx2 = tx + glyph->tw;
+      ty2 = ty + glyph->th;
 
-      glyph_x = floor (x + cx + 0.125) + glyph.draw_x;
-      glyph_y = floor (y + cy + 0.125) + glyph.draw_y;
-      glyph_w = glyph.draw_width;
-      glyph_h = glyph.draw_height;
+      glyph_x = floor (x + cx + 0.125) + glyph->draw_x;
+      glyph_y = floor (y + cy + 0.125) + glyph->draw_y;
+      glyph_w = glyph->draw_width;
+      glyph_h = glyph->draw_height;
 
       ops_draw (builder, (GskQuadVertex[GL_N_VERTICES]) {
         { { glyph_x,           glyph_y           }, { tx,  ty  }, },